package com.planet.biz;

import com.planet.db.dao.AssessmentUserMapper;
import com.planet.db.model.AssessmentUser;
import com.planet.facade.AssessmentUserBiz;
import com.planet.query.AssessmentUserQuery;
import com.planet.utils.CommonConverter;
import com.planet.vo.AssessmentUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jiayazi on 17/11/15.
 */
@Component("assessmentUserBiz")
public class AssessmentUserBizImpl implements AssessmentUserBiz{

    @Autowired
    AssessmentUserMapper assessmentUserMapper;

    @Override
    public boolean insertSelective(AssessmentUserQuery assessmentUserQuery) {
        return assessmentUserMapper.insertSelective(assessmentUserQuery);
    }

    @Override
    public AssessmentUserVO selectByPhoneAndType(String phone) {
        AssessmentUser assessmentUser = assessmentUserMapper.selectByPhone(phone);
        AssessmentUserVO assessmentUserVO = new AssessmentUserVO();
        CommonConverter.convert(assessmentUser,assessmentUserVO);
        return assessmentUserVO;
    }

    @Override
    public AssessmentUserVO selectByPhone(String phone) {
        AssessmentUser assessmentUser = assessmentUserMapper.selectByPhone(phone);
        AssessmentUserVO assessmentUserVO = new AssessmentUserVO();
        CommonConverter.convert(assessmentUser,assessmentUserVO);
        return assessmentUserVO;
    }

    @Override
    public boolean updateAssessState(AssessmentUserQuery assessmentUserQuery) {
        return assessmentUserMapper.updateAssessState(assessmentUserQuery);
    }

    @Override
    public List<AssessmentUserVO> selectHaveAssessList() {
        List<AssessmentUser> assessmentUsers = assessmentUserMapper.selectHaveAssessList();
        List<AssessmentUserVO> assessmentUserVOS = new ArrayList<>(assessmentUsers.size());
        CommonConverter.convertList(AssessmentUserVO.class,assessmentUsers,assessmentUserVOS);
        return assessmentUserVOS;
    }

    @Override
    public List<AssessmentUserVO> selectNoHaveAssessList() {
        List<AssessmentUser> assessmentUsers = assessmentUserMapper.selectNoHaveAssessList();
        List<AssessmentUserVO> assessmentUserVOS = new ArrayList<>(assessmentUsers.size());
        CommonConverter.convertList(AssessmentUserVO.class,assessmentUsers,assessmentUserVOS);
        return assessmentUserVOS;
    }

    @Override
    public boolean assess(AssessmentUserQuery assessmentUserQuery) {
        return assessmentUserMapper.assess(assessmentUserQuery);
    }
}
